package com.gitee.wsl.unit.angle.ext

import com.gitee.wsl.unit.angle.AngleUnit

fun AngleUnit.inBetweenInclusive(min: AngleUnit, max: AngleUnit): Boolean = inBetween(min, max, inclusive = true)
fun AngleUnit.inBetweenExclusive(min: AngleUnit, max: AngleUnit): Boolean = inBetween(min, max, inclusive = false)

infix fun AngleUnit.inBetween(range: ClosedRange<AngleUnit>): Boolean = inBetween(range.start, range.endInclusive, inclusive = true)
infix fun AngleUnit.inBetween(range: OpenEndRange<AngleUnit>): Boolean = inBetween(range.start, range.endExclusive, inclusive = false)

fun AngleUnit.inBetween(min: AngleUnit, max: AngleUnit, inclusive: Boolean): Boolean {
    val nthis = this.normalized
    val nmin = min.normalized
    val nmax = max.normalized
    @Suppress("ConvertTwoComparisonsToRangeCheck")
    return when {
        nmin > nmax -> nthis >= nmin || (if (inclusive) nthis <= nmax else nthis < nmax)
        else -> nthis >= nmin && (if (inclusive) nthis <= nmax else nthis < nmax)
    }
}

//operator fun ClosedRange<AngleUnit>.contains(angle: AngleUnit): Boolean = angle.inBetween(this.start, this.endInclusive, inclusive = true)
//operator fun OpenEndRange<AngleUnit>.contains(angle: AngleUnit): Boolean = angle.inBetween(this.start, this.endExclusive, inclusive = false)
//infix fun AngleUnit.until(other: AngleUnit) = this ..< other
